<?php
namespace Home\Controller;
use Think\Controller;

/**
 * Index Display Controller
 *
 * @package Home\Controller
 * @author lythesia
**/
class IndexController extends Controller {
  /**
   * Display index page
   *
   * @return 
   * @author lythesia
   **/
  public function index(){
    $opt = array(
      'page'  => '1',
      'count' => '12',
      'order' => 'rating desc',
    );
    $opt_side = array(
      'rel'   => 'director',
      'page'  => '1',
      'count' => '12',
      'order' => 'releasedate desc,rating desc',
    );
    $field = 'id,title,releasedate,rating,poster';

    $data = A('Common/Movie')->getTopNewMovies($opt, $field);
    if(!$data) goto error;

    $data_side = A('Common/Movie')->getTopNewMovies($opt_side, $field);
    $genre = A('Common/Genre')->getGenres(array(
    'field' => 'id,name', 'limit' => '6'));

    $this->assign('data', $data);
    $this->assign('data_side', $data_side);
    $this->assign('genre', $genre);
    $this->assign('spec_content', 'Movie/movie-slides');

    $this->display('Movie/index-base');
    return;

    error:
    $this->display('Common/404');
  }


  /**
   * Display genre list page
   *
   * @return 
   * @author lythesia
   **/
  public function genres() {
    $opt = array(
      'field' => ['id', 'name'],
    );
    $data = A('Common/Genre')->getGenres($opt);
    if(!$data) goto error;

    $this->assign('data', $data);
    $this->display('Movie/genre-list');
    return;

    error:
    $this->display('Common/404');
  }


  /**
   * Display error page
   *
   * @return 
   * @author lythesia
   **/
  public function page_error() {
    $this->display('Common/404');
  }
}
